package com.lemon.exam.repository;

import com.lemon.exam.common.entity.view.ViewClassGradeUserJob;
import com.lemon.exam.entity.po.ClassPO;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.r2dbc.repository.R2dbcRepository;
import reactor.core.publisher.Flux;

import java.util.List;


/**
 * 班级表 数据访问接口
 *
 * @author Lemon
 * @since 2025/04/20 22:06:24
 */
public interface ClassRepository extends R2dbcRepository<ClassPO, Long> {
    @Query("""
            SELECT class_id, class_name, grade_id, grade_name FROM view_class_grade_user_job
            WHERE class_deleted = 0 AND grade_deleted = 0 AND user_status = 1 AND user_deleted = 0
            AND job_deleted = 0 AND user_id = :userId
            """)
    Flux<ViewClassGradeUserJob> findClassByUserId(Long userId);

    @Query("""
            SELECT DISTINCT class_id, class_name, grade_id, grade_name FROM view_class_grade_user_job
            WHERE class_deleted = 0 AND grade_deleted = 0
            """)
    Flux<ViewClassGradeUserJob> findAllClassGrade();

    @Query("SELECT DISTINCT class_id, class_name, grade_name FROM view_class_grade_user_job WHERE class_id IN (:idList)")
    Flux<ViewClassGradeUserJob> findClassNameGradeNameById(List<Long> idList);
}
